﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace WebCacheHelper
{
	/// <summary>
	/// A strongly typed wrapper for Session variables.
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class Session<T>
	{
		private string Name;
		
		/// <summary>
		/// Creates a new session object with a GUID for a name.
		/// </summary>
		public Session()
		{							
			Name = Guid.NewGuid().ToString();
		}

		/// <summary>
		/// Creates a new session object with the specified name.
		/// </summary>
		public Session(string name)
		{
			Name = name;
		}

		/// <summary>
		/// Get or set your value for the Session.
		/// </summary>
		public T Value
		{
			get 
			{
				object o = HttpContext.Current.Session[Name];
				if (o is T)
					return (T)o;
				else
					return default(T);
			}
			set 
			{
				HttpContext.Current.Session[Name] = value;
			}
		}
	}	
}
